package ssl

import (
	"crypto/tls"
	"sync"

	"golang.org/x/crypto/acme/autocert"
)

type CertManager struct {
	manager *autocert.Manager
	cache   autocert.Cache
	domains []string
	mu      sync.RWMutex
}

func NewCertManager(cacheDir string, domains []string) *CertManager {
	return &CertManager{
		cache:   autocert.DirCache(cacheDir),
		domains: domains,
	}
}

func (cm *CertManager) GetTLSConfig() *tls.Config {
	return &tls.Config{
		GetCertificate:           cm.manager.GetCertificate,
		PreferServerCipherSuites: true,
		MinVersion:               tls.VersionTLS12,
	}
}
